package com.atguigu.gulimall.auth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @Author : Jungle
 * @Description :  定义cookie子父域名共享
 */
@Configuration
public class GulimallSessionConfig {
    @Bean
    public  CookieSerializer  cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        //放大作用域
        cookieSerializer.setDomainName("gulimall.com");
        //默认名字是 SESSION
        cookieSerializer.setCookieName("GULISESSION");
        return cookieSerializer;
    }

    /**
     *
     * 默认的序列化方式需要实现Serializable 接口
     * 
     * 修改序列化方式json序列化
     * 优点是速度快,序列化后的字符串短小精悍,
     * 不需要实现Serializable接口
     * 便于查看数据
     *
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }
}
